package com.example.wheelviewdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private WheelView wv;
    private TextView tv;
    private final List<String> list= Arrays.asList("鲁班","后羿","猴子","猪八戒","妲己","安琪拉","孙尚香");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        wv=findViewById(R.id.wv);
        tv=findViewById(R.id.tv);
        wv.setItems(list);
        wv.setSeletion(2);
        wv.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                tv.setText("您选择的英雄是："+selectedIndex+"-"+item);
            }
        });
    }
}